package com.why.cachecloud.service.stats.app;

import com.why.cachecloud.configuration.constant.DataFormatCheckResult;
import com.why.cachecloud.configuration.constant.HorizontalResult;
import com.why.cachecloud.entity.*;

import java.util.List;

/**
 * app相关发布操作
 * Created by why.developer on 14-10-20.
 */
public interface AppDeployCenter {

    /**
     * 新建应用
     *
     * @param appDesc
     * @param appUser
     * @param memSize
     */
    boolean createApp(AppDesc appDesc, AppUser appUser, String memSize);

    /**
     * 为应用分配资源
     *
     * @param appAuditId
     * @param nodeInfoList <br/>格式=masterIp:空间:slaveIp
     * @param auditUser
     * @return
     */
    boolean allocateResourceApp(Long appAuditId, List<String> nodeInfoList, AppUser auditUser);


    /**
     * 为API应用分配的资源格式检测
     *
     * @param appDeployText
     * @return
     */
    DataFormatCheckResult checkAppDeployDetail4Api(AppInfoApi appInfoApi, String appDeployText, RedisVersion redisVersion);

    /**
     * 下线应用
     *
     * @param appId
     * @return
     */
    long offLineApp(Long appId, AppUser userInfo, Long auditId);

    /**
     * 修改应用下节点配置
     *
     * @param appId
     * @param appAuditId
     * @param key
     * @param value
     * @return
     */
    boolean modifyAppConfig(Long appId, Long appAuditId, String key, String value);

    /**
     * 垂直扩展
     *
     * @param appId
     * @param appAuditId
     * @param memory     单位MB
     * @return
     */
    boolean verticalExpansion(Long appId, Long appAuditId, long operateId, int memory);

    /**
     * 检测水平扩容节点
     *
     * @param appAuditId
     * @param masterSizeSlave
     * @return
     */
    DataFormatCheckResult checkHorizontalNodes(Long appAuditId, String masterSizeSlave);

    /**
     * 检查水平扩容的格式
     *
     * @param appId
     * @param appAuditId
     * @param sourceId
     * @param targetId
     * @param startSlot
     * @param endSlot
     * @param migrateType
     * @return
     */
    HorizontalResult checkHorizontal(long appId, long appAuditId, long sourceId, long targetId, int startSlot,
                                            int endSlot, int migrateType);


    /**
     * 开始水平扩容
     *
     * @param appId
     * @param appAuditId
     * @param sourceId
     * @param targetId
     * @param startSlot
     * @param endSlot
     * @param migrateType
     * @return
     */
    HorizontalResult startHorizontal(long appId, long appAuditId, long sourceId, long targetId, int startSlot,
                                            int endSlot, int migrateType);

    /**
     * 重试水平扩容
     *
     * @param instanceReshardProcessId
     * @return
     */
    HorizontalResult retryHorizontal(final int instanceReshardProcessId);

    /**
     * 添加cluster一个主(从)节点
     *
     * @param appId
     * @param masterHost
     * @param slaveHost  从节点可为空
     * @param memory
     * @return
     */
    boolean addHorizontalNodes(Long appId, String masterHost, String slaveHost, int memory);


    /**
     * 获取当前水平扩展进度列表
     *
     * @return
     */
    List<InstanceReshardProcess> getHorizontalProcess(long auditId);


    /**
     * 清理应用数据
     *
     * @param appId
     * @param appUser
     * @return
     */
    boolean cleanAppData(long appId, AppUser appUser);


}
